
<template>
 <div  class="components-container">
     
    <sweet-modal ref="dialog" class="dialog" v-bind:blocking="true">
      <h3>{{ title }}</h3>
  
      <div style="min-height:200px; margin:30px 50px">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">业务名称</label>
                <div class="layui-input-inline">
                  <el-select v-model="userData.CBBNAME" placeholder="请选择业务名称" style="width:100%" >
                    <el-option  v-for="item in GetSFLY" :key="item.value" :label="item.label" :value="item.value" :disabled="isinfo"></el-option>
                  </el-select>
                </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">名称描述</label>
              <div class="layui-input-inline">
                  <el-input v-model="userData.CBBALIAS" placeholder="请输入名称描述" :readonly="isinfo"></el-input>
              </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">收费类别</label>  
                <div class="layui-input-inline">
                    <el-select v-model="userData.CBBCYPID" placeholder="收费类别" :disabled="isinfo" filterable @change="changetypes($event)">
                        <el-option v-for="item in chargetype" :key="item.CYPID" :label="item.CYPNAME" :value="item.CYPID"></el-option>
                    </el-select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
                <label class="layui-form-label">收费项目</label>
                <div class="layui-input-inline">
                    <el-select v-model="List_Census" placeholder="收费项目" multiple :disabled="isinfo" filterable style="    width: 493px;">
                        <el-option v-for="item in chargepro" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </div>
            </div>
        </div>
      </div>

      <div class="layui-form-item btnCenter" z-index=100>
          <el-button @click="closeDialog">取消</el-button>
          <el-button type="primary" @click="submit" :loading="this.$store.state.isloading">确定</el-button>
      </div>
    </sweet-modal>
 </div>
</template>

<script>
import sweetModal from "@/components/sweetModal";
import apiBase from "@/api/apiBase.js";
const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";
export default {
  data() {
    return {
     
      title: null,
      btnListIfon: [],
      GetSFLY: [],
      chargetype: [],//收费类别
      chargepro: [],// 收费项目
      userDeptNos:[],
      List_Census:[],
      isinfo: null,
      ids:null,
      
      userData: {
        CBBNAME:null,
        CBBALIAS: null,
        CBBCYPID: null, //收费类别
      },
      roles:null
      
     }
   },
   methods: {
      //功能操作
      open(order, id) {
        this.order = order;
        this.ids = id;
        this.changetypes();
        this.GetSFLYS();
        this.getAllCharge();
        this.dataRepeat();
        switch (this.order) {
          case ADD:
            this.title = "收费项目新增";
            this.isinfo = false;
            this.$refs.dialog.open();
            break;
          case MODIFY:
            this.title = "修改";
            this.isinfo = false;
            this.dataInfo(id);
            this.$refs.dialog.open();
            break;
          case INFO:
            this.title = "详情";
            this.isinfo = true;
            this.dataInfo(id);
            this.$refs.dialog.open();
            break;
          case DELETE:
            this.dataDelete(id);
            break;
          default:
        }
      },
    //数据重置
    dataRepeat() {
        this.userData = {};
        this.List_Census = [];
        this.userData.CBBCYPID = null;
        this.chargepro = [];
    },
    //提交
    submit() {
      this.$store.state.isloading = true;
      switch (this.order) {  
        case ADD:
          this.dataAdd();
          break;
        case MODIFY:
          this.dataModify();
          break;
        case DELETE:
          break;
        case INFO:
          this.$refs.dialog.close();
        
          break;
        default:
      }
    },
    //收费类别改变触发
    changetypes(val){
      var data = {
        Data: {
          ChacypidEqual: val
        }
      };
      apiBase.DoService(data, apiBase.getApiAdress().Checkout.GetAllCharge, res => {
        let userDptDatas = res.data.content.OutData;
        var  legendsDptsData = userDptDatas.map(item => ({
            label: item.CHANAME,
            value: item.CHAID
          }));
        this.chargepro = legendsDptsData;
      });
    },
    //获取收费来源
    GetSFLYS() {
      var data = {};
      apiBase.DoService(data, apiBase.getApiAdress().CostDeploy.GetSFLY, res => {
        let userDptData = res.data.content;
        var  legendsDptsData = userDptData.map(item => ({
            label: item.CODNAME,
            value: item.CODALIAS
          }));
        this.GetSFLY = legendsDptsData;
      });
    },
     //收费项目
      getAllCharge() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().ChargeProject.QueryType,
          res => {
            this.chargetype = res.data.content;
          }
        );
      },
     //收费类别
      getAllChargeType() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Code.GetSFLY,
          res => {
            // this.chaList = JSON.parse(JSON.stringify(this.allCharge));

            this.allCharge = res.data.content.OutData;
            this.chargepro = JSON.parse(JSON.stringify(this.allCharge));
          }
        );
      },
    //修改
    dataModify() {
      let Data = JSON.parse(JSON.stringify(this.userData));
      let list_Cbl = [];
      if(this.List_Census){
        for(var i = 0; i<this.List_Census.length;i++){
            list_Cbl.push({CBLCHAID: this.List_Census[i]});
        }
      };
      Data.list_Cbl = list_Cbl;
      Data.CBBID = this.ids;
      apiBase.DoService(Data, apiBase.getApiAdress().CostDeploy.Modify, res => {
        this.$refs.dialog.close();
        this.refreshData();
        this.$message({
          type: "success",
          message: "修改成功!"
        });
        this.refreshData();
      }, res =>{
        this.$message.error(res.data.msg);
      
      
      });
    },
    //新增提交
    dataAdd() {
      let Data = JSON.parse(JSON.stringify(this.userData));
      let list_Cbl = [];
      if(this.List_Census){
        for(var i = 0; i<this.List_Census.length;i++){
            list_Cbl.push({CBLCHAID: this.List_Census[i]});
        }
      };
      Data.list_Cbl = list_Cbl;
      apiBase.DoService(Data, apiBase.getApiAdress().CostDeploy.Create, res => {
        this.$refs.dialog.close();
        this.refreshData();
        this.$message({
          type: "success",
          message: "新增成功!"
        });
      }, res =>{
        this.$message.error(res.data.msg);
      });
    },
    //详情
    dataInfo(id) {
      let data = {
        CBBID: id
      };

      apiBase.DoService(data, apiBase.getApiAdress().CostDeploy.Detail, res => {
        
        this.userData = res.data.content;
        // this.List_Census = 
        for(var i in this.userData.list_Cbl){
            this.List_Census.push(this.userData.list_Cbl[i].CBLCHAID);
        }
      //  this.changetypes(res.data.content.CBBCYPID);

        // let userRoles=[];
        // let legendsModifyData = res.data.content.Rols.map(item => ({
        //     label: item.ROLNAME,
        //     value: item.ROLID
        //   }));
        
        // legendsModifyData.forEach((item, index) => {
        //  userRoles.push(item.label);
         
        // })
      
        // this.roles=userRoles.join(',')
    
        
      });
    },
    // 删除表格列
    dataDelete(id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(callback => {
          let data = {
            CBBID: id
          };
          apiBase.DoService(data, apiBase.getApiAdress().CostDeploy.Delete , res => {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.refreshData();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
      },
      refreshData() {
      this.$emit("refreshData");
    },
      closeDialog() {
       this.$refs.dialog.close();
      },
   },
   components: {
       sweetModal
   }
 }
</script>

<style>

</style>
